package priv.happy;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.junit.*;
import priv.happy.pojo02.J20;
import priv.happy.pojo02.Transport;
import priv.happy.pojo02.Yadea;
import priv.happy.util.SessionFactoryUtil;

/**
 * @Author: HAPPY
 * @Project_name: hibernate
 * @Package_name: priv.happy
 * @Date: 2021/10/11 8:40
 * explain:
 *  union-subclass继承父类
 */
public class MyTest02 {
    static SessionFactory sessionFactory;
    static Session session;

    @BeforeClass
    public static void beforeClass() throws Exception {
        sessionFactory = SessionFactoryUtil.getSessionFactory();
    }

    @AfterClass
    public static void afterClass() throws Exception {
        sessionFactory.close();
    }


    @Before
    public void setUp() throws Exception {
        session = sessionFactory.openSession();
    }

    @After
    public void tearDown() throws Exception {
        session.close();
    }

    @Test
    public void test01() {
        Transaction transaction = session.beginTransaction();
        Transport transport = new Transport();
        //transport.setId(1001);
        transport.setName("普通交通工具");
        transport.setRunType("地上跑的");
        session.save(transport);
        transaction.commit();
    }

    @Test
    public void test02() {
        Transaction transaction = session.beginTransaction();
        Yadea yadea = new Yadea();
        //yadea.setId(1003);
        yadea.setSource("电动");

        yadea.setName("雅迪电动车");
        yadea.setRunType("两个轮子转着跑");
        session.save(yadea);
        transaction.commit();
    }

    @Test
    public void test03() {
        Transaction transaction = session.beginTransaction();
        J20 j20 = new J20();
        //j20.setId(1001);
        j20.setAttack("DF-41");
        session.save(j20);
        transaction.commit();
    }
}
